package com.yangye.pidoublename.service.impl;

import com.alibaba.fastjson.JSON;
import com.yangye.pidoublename.service.DoubleNameService;
import com.yangye.pidoublename.service.ProvinceEnum;
import com.yangye.pidoublename.vo.DoubleNameVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author yangye
 * @date 2019/9/19
 */
@Service
public class AnHuiServiceImpl implements DoubleNameService {

	@Autowired
	private RestTemplate restTemplate;

	private final String QUERY_URL = "http://www.ahga.gov.cn:8087/was2/ahsga/queryNewName.action?fn=query&SJLYSD=全省&XM=";

	@Override
	public DoubleNameVo findByName(String name) {
		String result = restTemplate.getForObject(QUERY_URL + name, String.class);
		Integer total = JSON.parseObject(result).getInteger("result");
		DoubleNameVo doubleNameVo = new DoubleNameVo();
		doubleNameVo.setName(name);
		doubleNameVo.setProvince(ProvinceEnum.ANHUI.getName());
		doubleNameVo.setTotal(total);
		return doubleNameVo;
	}

}
